using System.Collections.Generic;
using System.Data.SQLite;
using WordsHelper.DAL.Services.Data;
using WordsHelper.Model.Data;
using System;

namespace WordsHelper.DAL.Models.Data
{
    public class DALDataTable
    {
        public List<ModelDataTable> Lists { get; set; }
        internal List<ModelDataTable> cache;

		/// <summary>
        /// 生成count=0的列表，已存入缓存。没有数据库操作。
        /// </summary>
        public DALDataTable()
        {
            Lists = new List<ModelDataTable>();
            cache = new List<ModelDataTable>();
        }
		/// <summary>
        /// 按条件查询列表，未存入缓存。有数据库操作。
        /// </summary>
        /// <param name="strWhere">条件：不要包括“where”，当为null或string.Empty时为无条件查询。</param>
        /// <exception cref="SQLiteException"></exception>
		public DALDataTable(string strWhere)
        {
            Lists = DALDataTableService.GetModelList(strWhere);
        }
		/// <summary>
        /// 按条件查询分页列表，未存入缓存。有数据库操作。
        /// </summary>
        /// <param name="strWhere">条件：不要包括“where”，当为null或string.Empty时为无条件查询。</param>
        /// <param name="strOrderby">排序字段，不要包括“order by”,当为null或string.empty是为默认排序</param>
        /// <param name="limit">所取的记录数</param>
        /// <param name="offset">跳过的记录数</param>
        /// <exception cref="SQLiteException"></exception>
        /// <exception cref="ArgumentException"></exception>
        public DALDataTable(string strWhere, string strOrderby, int limit, int offset)
        {
            if (limit < 0)
            {
                throw new ArgumentException("Is Negative.", "limit");
            }
            if (offset < 0)
            {
                throw new ArgumentException("Is Negative.", "offset");
            }
            Lists = DALDataTableService.GetModelList(strWhere, strOrderby, limit, offset);
        }
    }
}